<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>车辆信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css">
<!--    <link rel="stylesheet" href="../../layui-v2.6.8/layui/layui.js" media="all">-->
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<!--<blockquote class="layui-elem-quote layui-text">-->
<!--    鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>-->
<!--</blockquote>-->

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>车辆信息添加页面</legend>
</fieldset>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">司机信息</label>
        <div class="layui-input-block">
            <select id="eid" name="eid" lay-verify="required" lay-filter="s">
                <option value="">请选择</option>
            </select>
            <a href="addDirver.html" class="layui-btn layui-btn-danger layui-btn-xs">添加司机信息</a>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号</label>
        <div class="layui-input-inline">
            <input type="text" id="vnumber" required lay-verify="required" placeholder="请输入车牌号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">车类型</label>
        <div class="layui-input-block">
            <select id="vtype" lay-verify="required">
                <option value=""></option>
                <option value="电动车">电动车</option>
                <option value="货车">货车</option>
                <option value="轿车">轿车</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">车辆状态</label>
        <div class="layui-input-block">
            <select id="vstatus" lay-verify="required">
                <option value=""></option>
                <option value="运输">运输</option>
                <option value="空闲">空闲</option>
                <option value="保养">保养</option>
                <option value="维修">维修</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="insert_1()">添加</button>
        </div>
    </div>
</form>
<script src="../../layui-v2.6.8/layui/layui.js"></script>
<script>
    function insert_1(){
      var $ = layui.$;
      var vnumber =$("#vnumber").val();
      var eid =$("#eid").val();
      var vtype =$("#vtype").val();
      var vstatus =$("#vstatus").val();
      console.log(vnumber);
      var data ={
        "vnumber":vnumber,
        "eid":eid,
        "vtype":vtype,
        "vstatus":vstatus,
      }
      var layer=layui.layer;
      var url ="http://localhost:8080/addVeh";
        $.ajax({
            url:url,
            type:"get",
            dataType:"json",
            async:true,
            // cache:false,
            data:data,
            success: function(data){
                console.log(data)
                if (data.code == 0) {

                    layer.msg("添加成功", {icon: 6,time:1800});
                    setTimeout(function (){
                        // location.href = '../car/addCar.html';
                    });
                    window.location.href = 'carIndex.html';
                } else {
                    layer.msg("添加失败", {icon: 5});
                }
                return false;
            }
        });
    }
    layui.use(['form','layer'],function() {
        var form = layui.form;
        var $ = layui.$;
        // var layer = layui.layer;
        form.on('select(s)', function (data) {
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/searchByEpost',
                dataType: 'json',
                async: false,
                // cache: false,
                success: function (data) {
                    $.each(data.data, function (index, item) {
                        $('#eid').append(new Option(item.ename, item.eid))

                    });
                    layui.form.render("select");
                }
            })
        });
    });
</script>
